
const { getAllFoods, getDetails, searchFoods,
    addCollection, addBrowse, } = require('../dao/modules/foodsDao');

//获取所有菜谱
module.exports.getAllFoods = async (val) => {
    const data = await getAllFoods(val);
    if (data.total) {
        return {
            status: 1,
            message: '获取数据成功',
            data
        }
    } else {
        return {
            status: 0,
            message: '获取数据失败',
            data
        }
    }
}

//获取菜谱详情
module.exports.getDetails = async (_id) => {
    const data = await getDetails(_id);
    if (data.length) {
        return {
            status: 1,
            message: '获取数据成功',
            data
        }
    } else {
        return {
            status: 0,
            message: '获取数据失败',
            data
        }
    }
}


//搜索菜谱

module.exports.searchFoods = async (val) => {
    const data = await searchFoods(val);
    if (data.total) {
        return {
            status: 1,
            message: '获取数据成功',
            data
        }
    } else {
        return {
            status: 0,
            message: '获取数据失败',
            data
        }
    }
}



//收藏菜谱

module.exports.addCollection = async (_id) => {
    const data = await addCollection(_id);
    if (data.focus) {
        if (data.data.nModified) {
            return {
                status: 1,
                message: '收藏成功',
                data: data.data
            }
        } else {
            return {
                status: 0,
                message: '收藏失败',
                data: data.data
            }
        }
    } else {
        if (data.data.nModified) {
            return {
                status: 1,
                message: '取消收藏成功',
                data: data.data
            }
        } else {
            return {
                status: 0,
                message: '取消收藏失败',
                data: data.data
            }
        }
    }
}



//新增浏览记录

module.exports.addBrowse = async (val) => {
    const data = await addBrowse(val);
    if (data.nModified) {
        return {
            status: 1,
            message: '新增浏览成功',
            data: data.data
        }
    } else {
        return {
            status: 0,
            message: '新增浏览失败',
            data: data.data
        }
    }
}








